package com.xj.ideatest.dialog;

import com.xj.ideatest.dao.XmxxMapper;
import com.xj.ideatest.model.XmglXtXmxx;
import com.xj.ideatest.utils.MybatisUtil;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.util.List;

public class JkglForm {
    private JTable jkdyTable;
    private JPanel root;
    private JButton addRowBtn;

    public JkglForm() {
        addRowBtn.addActionListener(actionEvent -> {
            DefaultTableModel model = (DefaultTableModel) jkdyTable.getModel();
            model.addRow(new Object[]{1, "名称", "描述", "get"});
        });
        // 列名最好用final修饰
        final Object[] columnNames = {"序号", "项目名称", "项目描述", "项目标识"};
        Object[][] rowData = {};
        DefaultTableModel dataModel = new DefaultTableModel(rowData, columnNames) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        jkdyTable.setModel(dataModel);

        XmxxMapper xmxxMapper = MybatisUtil.getMapper(XmxxMapper.class);
        XmglXtXmxx xmglXtXmxx = new XmglXtXmxx();
        List<XmglXtXmxx> xmglXtXmxxes = xmxxMapper.queryXmlb(xmglXtXmxx);
        System.out.println(xmglXtXmxxes);

        for (int i = 0; i < xmglXtXmxxes.size(); i++) {
            XmglXtXmxx xtXmxx = xmglXtXmxxes.get(i);
            dataModel.addRow(new Object[]{i + 1, xtXmxx.getXmmc(), xtXmxx.getXmms(), xtXmxx.getXmbs()});
        }
    }

    public JComponent getComponent() {
        return root;
    }
}
